package org.trinity.netdisk.enums;

import java.util.ArrayList;
import java.util.List;

/**
 * API 统一返回状态码
 */
public enum ResultCode {

	/* 成功状态码 */
	SUCCESS(20000, "成功"),

	/* 参数错误：10001-19999 */
	PARAM_IS_INVALID(10001, "参数无效"),
	PARAM_IS_BLANK(10002, "参数为空"),
	PARAM_TYPE_BIND_ERROR(10003, "参数类型错误"),
	PARAM_NOT_COMPLETE(10004, "参数缺失"),
	NO_PERMISSION(10005,"没有权限"),

	/* 用户错误：20001-29999*/
	USER_NOT_LOGGED_IN(20001, "用户未登录"),
	USER_LOGIN_INCORRECT_USERNAME_OR_PASSWD(20002, "用户名或密码错误"),
	USER_ACCOUNT_FORBIDDEN(20003, "账号已被禁用"),
	USERNAME_HAS_EXISTED(20005, "用户名已存在"),
	USER_NOT_UPDATE(20008, "用户更新失败"),
	USER_ADD_SUCCESS(20009, "用户注册成功"),
	USER_ADD_NOT(20010, "用户注册失败"),
	USER_LOGIN_SUCCESS(20011, "登录成功"),
	INVALID_VERIFICATION_CODE(20012,"验证码不正确"),
	EXIST_EMAIL(20013,"邮箱已存在"),
	NOT_EXIST_EMAIL(20014,"邮箱不存在"),
	SHARE_LINK_EXPIRED(20015,"文件分享链接过期"),
	INVALID_SHARE_DAYS(20016,"文件分享天数有误"),
	/* 业务错误：30001-39999 */
	SPECIFIED_QUESTIONED_USER_NOT_EXIST(30001, "某业务出现问题"),
	FILE_SIZE_LIMIT_EXCEEDED(30001,"上传文件超过最大限制"),
	SECOND_PASS_FAILED(30002,"不支持秒传业务"),
	/* 系统错误：40001-49999 */
	SYSTEM_INNER_ERROR(40001, "系统繁忙，请稍后重试"),
	OPERATION_FAILED(40002,"操作失败"),

	/* 数据错误：50001-599999 */
	DATA_NOT_FOUND(50001, "数据未找到"),
	DATA_IS_WRONG(50002, "数据有误"),
	DATA_ALREADY_EXISTED(50003, "数据已存在"),
	SHARE_FILE_CHECK_CODE_ERROR(50004,"分享验证码错误"),

	/* 接口错误：60001-69999 */
	INTERFACE_INNER_INVOKE_ERROR(60001, "内部系统接口调用异常"),
	INTERFACE_OUTTER_INVOKE_ERROR(60002, "外部系统接口调用异常"),
	INTERFACE_FORBID_VISIT(60003, "该接口禁止访问"),
	INTERFACE_ADDRESS_INVALID(60004, "接口地址无效"),
	INTERFACE_REQUEST_TIMEOUT(60005, "接口请求超时"),
	INTERFACE_EXCEED_LOAD(60006, "接口负载过高"),

	/* 权限错误：70001-79999 */
	PERMISSION_NO_ACCESS(70001, "无访问权限"),

	/* 文件错误 80000-89999*/
	FILE_WITH_DUPLICATE_NAME(80000, "文件名已存在"),
	USER_FILE_INSERT_ERROR(80001,"用户文件关联表插入失败"),
	RENAME_USER_FILE_FAILED(80002,"文件重命名失败"),
	TARGET_NOT_DIR(80003,"移动目标位置不是文件夹"),
	NO_ENOUGH_SPACE(80004,"用户没有足够的存储空间"),
	NO_FILE_NAME(80005,"文件名不能为空"),
	FILE_NOT_FOUND(80006,"文件不存在");


	private final Integer code;

	private final String message;

	ResultCode(Integer code, String message) {
		this.code = code;
		this.message = message;
	}

	public Integer getCode() {
		return code;
	}

	public String getMessage() {
		return message;
	}

	//校验重复的code值
	public static void main(String[] args) {
		ResultCode[] ApiResultCodes = ResultCode.values();
		List<Integer> codeList = new ArrayList<>();
		for (ResultCode ApiResultCode : ApiResultCodes) {
			if (codeList.contains(ApiResultCode.code)) {
				System.out.println(ApiResultCode.code);
			} else {
				codeList.add(ApiResultCode.getCode());
			}
		}
	}
}